refactored code into auth library