Move functions into script scope