Fix stack overflow error
This closes #236