Functions should not allocate memory. Move buffers out of function.