Fixed ROI changing and clearing issue, some refactoring