Template refactor

Fixes #5
Fixes #10