corrected to increment in while loops