break out of while loop instead of using close()