fixing bug in memory formula