Reworking the authentication and related to it code