reorganize the code into an allocator trait API