restored template functionality. still need code refactoring, but functionality first