Some code cleaning and added comments