refactor widget instance creation