tidied up errors and event emitter memory leaks