Updated function so can work with Symplified and ADFS