Use the menu type instead of assuming if the param1 is a valid widget then the menu is for a widget. The params are free form data which is specific to the menu type, so it is possible for it to unintentionally be a valid widget id even when it is something else.