Refactor code to add calibration error checking

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>