move timeout check inside condition