Cleaning up code and adding comments and basic documentation.