added a state check