Optimized solution LOGIC / fixed logic bug

Fixed a bug in now commented out code (which is the computationally
faster solution)
Optimized logic / readability of solution