replace memory ptr with reference