fix timeout logic