Found a lot better solution for the bug I found, the other solution was buggy itself.