Repair dynamic_array and do some trivial cleanup.