fixed problem with recursion resulting in stack level too deep error