Refactored templates. Fixes #4