added palcheck with recursion