added support for placeholders in inner_tmpl, minor refactoring optimizations