Having one subclass per type would make this code simpler.