Large refactor and breakdown of plugin.template.py