added comments and code cleaning