Tidied up the main script