Cleaning and reorganizing code