Added get template method and did a lot of refactoring.