fixed bug with recursive calls