reworked template into single file and rationalised token replacement