Add a state machine for connecting to help with stalling other code (still not ideal, as the main call blocks too long)