cleans up the while loop, implements more nexts and less breaks