Added comments and some cleanup