Refactoring: buffer copying optimized. Formatting fixed.