More unit tests.
Commiting pre-refactor work.
More test and fixes.
Small optimisation to ToValue()