fix the while loop at the end and indentation