add template expasion; fixes #7; some refactoring