fixed cast to mem