An apparatus configured to control power flow between a DC electric load and a mains input AC voltage supply, the apparatus configured to handle active power and reactive power in a bi-directional manner, the apparatus comprising: a full-bridge power inverter arranged as a bi-directional AC-DC power converter, the power converter having AC mains-side terminals and DC load-side terminals, wherein the AC mains-side terminals are arranged to be connected to the mains input AC voltage supply; a DC bulk capacitor connected in parallel to the DC load-side terminals of the power converter, the DC bulk capacitor being arranged to be connected in parallel with the electric load; a mains input AC voltage control means comprising: a synchronization circuit configured to receive the mains input AC voltage, V s; a comparator configured to compare the mains input AC voltage, V s, with a mains reference voltage, V s_ref, and output a difference signal, e Vs; an error amplifier/compensator configured to receive the difference signal, evs; a magnitude and phase angle circuit configured to receive signals based on an output from the error amplifier/compensator and on an output from the synchronization circuit, the magnitude and phase angle circuit further configured to generate at least two control variables including a magnitude, M, and a phase angle, σ, for a Pulse Width Modulation, PWM, voltage; a gate pattern generator arranged to receive the at least two control variables and generate the PWM voltage; wherein the gate pattern generator is further configured to drive the power converter based on the PWM voltage to control a mains input AC current magnitude and a mains input AC current phase angle with respect to the mains input AC voltage to regulate fluctuations in the mains input AC voltage with respect to the mains reference voltage. a full-bridge power inverter arranged as a bi-directional AC-DC power converter, the power converter having AC mains-side terminals and DC load-side terminals, wherein the AC mains-side terminals are arranged to be connected to the mains input AC voltage supply; a DC bulk capacitor connected in parallel to the DC load-side terminals of the power converter, the DC bulk capacitor being arranged to be connected in parallel with the electric load; a mains input AC voltage control means comprising: a synchronization circuit configured to receive the mains input AC voltage, V s; a comparator configured to compare the mains input AC voltage, V s, with a mains reference voltage, V s_ref, and output a difference signal, e Vs; an error amplifier/compensator configured to receive the difference signal, evs; a magnitude and phase angle circuit configured to receive signals based on an output from the error amplifier/compensator and on an output from the synchronization circuit, the magnitude and phase angle circuit further configured to generate at least two control variables including a magnitude, M, and a phase angle, σ, for a Pulse Width Modulation, PWM, voltage; a gate pattern generator arranged to receive the at least two control variables and generate the PWM voltage; wherein the gate pattern generator is further configured to drive the power converter based on the PWM voltage to control a mains input AC current magnitude and a mains input AC current phase angle with respect to the mains input AC voltage to regulate fluctuations in the mains input AC voltage with respect to the mains reference voltage. a synchronization circuit configured to receive the mains input AC voltage, V s; a comparator configured to compare the mains input AC voltage, V s, with a mains reference voltage, V s_ref, and output a difference signal, e Vs; an error amplifier/compensator configured to receive the difference signal, evs; a magnitude and phase angle circuit configured to receive signals based on an output from the error amplifier/compensator and on an output from the synchronization circuit, the magnitude and phase angle circuit further configured to generate at least two control variables including a magnitude, M, and a phase angle, σ, for a Pulse Width Modulation, PWM, voltage; a gate pattern generator arranged to receive the at least two control variables and generate the PWM voltage; wherein the gate pattern generator is further configured to drive the power converter based on the PWM voltage to control a mains input AC current magnitude and a mains input AC current phase angle with respect to the mains input AC voltage to regulate fluctuations in the mains input AC voltage with respect to the mains reference voltage.