Added comments, cleaned up code