progress on implementation of templating, currently very messy, workign on adding flexibility