added comments, cleaned up code a little bit.