updated to use a context manager to manage the timeout