Fix GetSID() when there's no W mapping, and refactor it to make it simpler.