Oh I see, looked over your code, seems I'll need full context to understand what's happening and what are you doing there. Looks to me, either it is okay depending on the task at hand or you could re-architect something.
You'd probably be better of with real code review instead of chat in here with that 🙂 If you do not have teammates who could do that, try stackoverflow's code review portal.