completed slave code