Fixed stack overflow exception

Closes #248