a bit of reorganisatio
very basic state machine