tidied up functions and dead code