This is very complex code and we need lots of unit tests to test just a fraction of what could be done with it.