some code cleaning, some added comments