a bit more re-organization and code consolidation