Thank you for looking into this. I have some code that keeps failing on me. So you are suggesting to move all function definitions outside the if __name__ == "__main__": ? Do you know what is the necessary parts that should be kept inside the statement?