redesign of repaint algorithm