adding template and state machine