Refactor of OAuth code.