Refactored code. Added extra checks for Single Signon. Removed settings that aren't going to be used