More in-depth unit test and a bug fix.