UNTESTED - huge cleanup of template files