first working implementation of template feature, probably needs some cleanup