code duplication removed using block
add state change example.