Added cancel feature and fixed concurrency bug.