Little refactoring; fixed error when no events were sorted