some cleaning and layout optimization