Added phpunit support and some tests

Refactor continues to remove weird brace notation
General tidying up and validation