CHANGE: refactored state machine and updated tracker to use it (doesn't quite work yet)