Refactor template parsing into submodule