added some comments and some code cleaning