Refactoring of authme function.