Fixed a bug which could cause goal stack overflow.