make key cleaning for templates recursive