handle empty templates
bug fixes