Refactor and deduplicate unauthorized function.