Fix timeout logic