Memory calculation fix