Fixes to mem alloc