fixing potential infinite loop and implement successive task termination attempts with timeout, closing #11