cleaned up template generation