Refactor

Large refactor tidying up the namespaces, adding tests etc