moved some mem alloc around