fixing bug in recursivity