changed interface to buffer protocol; split into to_buffer_a and to_buffer functions
Added drop-in custom memory management; some typo fixes