Redo database sycning, and add ability to logout