move all Python code to top level