Removed old code, added comments, and general cleanup.