Implemented login state management. Various fixes and adjustments.