Refactor, tighten up, and comment code.