Adding basic state machinery. Also might have to do defaults first.