Clean up and comments

Added comments to sections of code and cleaned up the formatting.