Refactor and extend authorization