end with a newline; also move some code in a separate function now that it is used from two places. OKd by j.