improvements on widget selection from code