Added comments and improvements.