refactored template compilation + template helpers