Another attempt at fixing autoreload, this time I think state machine was a bit wrong