implemented state machine inside control module