fixed to parse templates recursively