Tidied cleanup code