finalized login function