Cleanups: comments, moving some functions around, and so.