processEvents() function