Got rid of some unneeded allocations, added  more asserts