Move timeout checking to separate function