add Event detection function