Fix mem stage bug