updated master/slave code