refactoring device authentication