Added a few comments, cleaned up the code.