Fixed rankOutput to work with non-self identity masks