moved paint outside
optimised