Refactored WidgetHandler. Fixes #519