refactored for multi-login.