Added lots of comments, cleaned up a some code