Fixed the broken logic, seems to be working fine now.