refactoring in database and auth_man