Separate LOGIN_STATE_CHANGED event into login/logout.
Fix some review comments.