Cleaned up a little code and added comments.