Major refactor for multi-tenant, multi-purpose