Fix potentially exceeding call stack limit

Fixes #2590. Improves parsing time.
Merge pull request #2624 from gingerik/wkt-call-stack

Fix potentially exceeding call stack limit