code cleaning and improvements