rebase for bug 917227 and more fixes. more work for bug 757866