Debug for repaint problem and refactor