Cleaning up code organization and adding additional documentation.