Cancel scan

This PR fixes issue #318.
Explanation done in #318.