added missing braces for while loop