This should probably be emalloc and efree later. same with hm.