Added tests, refactored Template.pm.