tidied up internals