database access optimization, fix logout