write main process events loop