small changhes in recursive auxiliar function