Fixed loop cycle duration calculation.

Changed code so the time offset is stored directly after calculating the cycle duration instead of waiting for the entire cycle to happen first. Should give more accurate readings and sensor data now.