cleaning and optimizing code