added function to apply flats