moved "quit\n" check to top