Minor refactoring of login/logout process
Merge remote-tracking branch 'origin/phase-1'