Add tests for buffer wrapper+fix some bugs+tests pass+no leaks