refactor code

i knew do while loops were useless