DRYd out a ton of code, about 100 lines.