Original commit message from CVS: More state change fixes. Added/fixed some testcases. Threadsafety fixes.