Tidied up this script