refactored allocations and some new unit tests