corrected controller algorithm