Continuation of #684 but merged-forward. Also did a little code cleanup and added a new, passing test to the testfile.