wip fixed bug to do with ifdef/ifndef nesting.
Some cleanups and a new reg test.