Optimised the use of static variables in the PID loop.