fixes to invocation of context menu and getting control's ancestry; refactoring