Add template engine and bug fixes