Add cancelable mechanism and support in key import

Closes #323
Merge remote-tracking branch 'origin/master'