Improve Bug 818 fix, implement bug 806 fix