Tidied up to be put into production