Refactoring app to use the authentication code