Buffer implementation and tests