Replace long conditional with guard clauses
Use each instead of while loop