code cleaning and debugging