Restructure Widget code