Factor line editing out of main loop.