Fix algorithm for events generation