refactored to externalize templates and scripts