Code cleaning and reorganisation