fixed problem with crash if first event is empty. This solution is more elegant than the one proposed in a previous commit