Some code consolidation and clean-up