added proper timeout handling