Updated main loop to be interval based, not delay based. Centralized the debug logging to only report changes in state.