Implemented auth handler a bit more sophisticated way.