Improve authentication handling