adding asserts and logs, fixing bug in alloc