Writing the Optimal Outsourcing Agreement