matrix bug fixes