Small modifications to make the heterogeneous version correct.