Fixed a logic error

exists has a garbage value, so evaluating it in an if statement can cause weird behaviour.

Please excuse the extra line changes, my editor stripped some trailing whitespace.