Improved template engine and sourced out to separate file