Added comments, cleaned code a little