Testing work

Lots of new tests to test the attributewriter and extensive tdying and refactoring of same