Cleaned up comments, some light refactoring, and adding doc blocks.