implemented redraw
optimized code