added timeout functionality