Refactoring registration code