moves variables from function to top of template for functionality