fixed bug that lead to recursion and bad behavior