Tidied to set up as a package.