add timeout function (by Captain_fake)