Switching up the WindowsIdentity detection and adding a bit more defensive coding