fixed minor bug in state management code