refactor authorization code