sort functions, event emitter, tests