move function from middle of script