State machine working a bit better but still probs.