Define functions in events