Solved the source of the problem this code worked around