Changed timings as I tweaked the gears on the box
Added a debug mode
Tweaked timings again
Added a lock to cure some concurrency issues
Tidied up