a bit tidied up