changed style of the inner loop to single lined while loops to comply with previous styles