add logout, move functions to top