Magnetic energy flows during the current quench and termination of disruptions with runaway current plateau formation in JET and implications for ITER