Reduced and DRYied out the code.