add logout, fix some bugs