extract functions from if __name__ block