refactoring buffer restoring