main loop in slave