restore matrix properly