#488 Some code cleaning and adding comments