moves function def to top of script