optimize xtemplate. Fixes #570