Cleaned up code, added comments, and got rid of warnings.