Cleanup buffer implementation. Added unit test.