Made some changes to the authentication function