I am sure there is, maybe share your complete code, is always easier.
I am not a developer myself, so maybe others can help, but they won't if it is too much difficulty.

Everyone has limited time.