changed builder to state machine