almost working, but doesn't modify mem (still gives original value)