The behaviour-specific data was getting corrupted when the regrade recreated the first step, because $oldstep->get_behaviour_data() was stripping off the leading '-' characters from the names, and they were not being added back.