Rearchitected the optimiser code.  It now is logical at least but I still need to write some unit tests to verify we are getting the correct results.