Refactoring authorize - can't fix bug with SystemStackError