Events function.