JBIDE-18247 - better organized with better cancelation logic

This is a cleaned up version of the patch with better cancelation logic. Also, see inline notes
Honestly, not sure, but am unwilling to remove that line unless I am convinced it's useless. It's been there before, and it's not documented when it's needed, so I'm inclined to leave it.