Library hierarchy setup

- Set up functions library
- Modularized the authentication logic into a function for code
neatness and re-usability.