finalized login logic