modified logic to determine state