Fixed spath replace and added template selection