Refactoring extension code to preserve URL and principal