Refactor authorization