Fix #2936

Different approach to delete gateways with no class attached.