added processEvents method and some examples