redesigned code for keeping the timeout