This function is a terrific case where relying on switching on the type of your classes doesn't pay off well. You have five cases, four of which are doing very similar things.