Fixing logic and removing print statements