Optimized creaetRepaint function to help write less code