fix bug reported by Nicolas
Merge pull request #1296 from pascanur/disconnected_bug_scan_grad

fix bug reported by Nicolas