Partially resolved issue 213

The resolving speed is acceptable now, but `processDeclarations` still
get called too many times.
And I don't know how to write a test case to measure speed.