WIP
Tidy up debugging
Hopefully fix the tracking/state bug