Updated the logic and it should work now.