refactoring to use local variable bytebuffer