tidied up script