tidied up functions