move events to function.