Refactoring to reduce the flickering