removing the function calls out of the loops
removing the exit calls in favor of a simple sentinel