Moved functions around to bring them into proximity to their use. Add a comment.