Further improvements using IsWidget to simplify the logic