I'm not sure what I did but it seems to work on the test cases.  Sorcery.