fixed some state machine stuff