more work for bug 843004 - part 2. cleanups, bug fixes and less unsafeDereference