refactor redraw function