restructured init_ending_wires (tested)