code cleaning and fixing