Made requested changes
Swapped if and while around