Clean up some code, add some comments/documentation.