Some tidying. This needs a refactor