automated the gadget construction algorithm