fixes for bug 859170, ready to land. cleanup for bug 859170, also started to write a test