fixing bug for template/category cases