Minor Performance Optimizations:
* Return ASAP./Prevent executing any unnecessary operations if we return.
* Used De Morgan's laws to merge and simplify if statements.
Other Changes:
* C++ Style: Declared iterator variables inside the for loops they are used in.
* No logic changes have been made.
Approved by Daniel van Vugt.