fix stack level too deep errors