code tidied up