Moved repainting to use events