merged event function into one.