Fix buffer reuse bug and some formatting.