Fix bug in updateMem which caused a loop