wrote algorithm to assign event