merged stuff from the sendgrid branch