Refactoring for cleanup.  Some minor stability teaks to prevent a deadlock in some situations.