Move and rework login()