code cleaning, added comments