Refactor of auth