fixed bug where cancelling a running function would cause null pointer exception and report thread death error to the user.