Move main code out to lib_defeat