Refactoring to remove duplication in register functions