added check if template directory exists