How to move python functions to end of script