Fixed memory allocation bug detected by valgrind
Reworked buffer implementation to store a pointer to the start of its contents