Cleaned up code and added a few comments.