refactoring and fixes for Bug #11209