fixes and more tests for bugs 783499 and 808370. updated to the latest patch in bug 820524