did some code cleaning and added comments