Vishv dev

Changes based on feedback on 'Google SignIn' branch.
Consider extracting the function body from here into a separate function and apply tests to it. This code is rather complex, so it should be well tested.