Avoiding stackoverflows in some cases