Move calculation of timeout to as early as possible.