Added comments, and some unused code deleted