refactored to make login logic more logical...