Previous commit broke the actual functionality. The code was confusing and worked until the previous commit. The changes make it logically and functionally correct.