Debugging and clean up

Some clean up
Some changes based on debugging tests.
Parameterised stuff.
Ready for next debugging run.