double buffer refactoring