fix math on memory