moved timeout code