move function into template block