Fix ordering bug in type management