refactoring and check auth