fixed error with sys.exit inside factor()