Some DRYing up and refactoring