Bug fix in mem allocation