Fixed infinite loops due to recursion and fixed typo