added state logic