improve PEP8 compliance. rewrite some confusing comments. add debug code to catch next occurrence of heisenbug crash. small optimization in on_selection_modified_async by using generator