Refactoring with buffer class