Refactoring of auth and some clean up.