code cleaning and comments added