ADDED COMMENTS AND REMOVED SOME DEBUG STATEMENTS