Fixed multi-threading memoization issue reported by Jared and David.

Thanks to Jared, who supplied a really helpful example provoking the bug.