move script higher to have fns defined earlier