CRM-16168 api chaining fix (plus some test tidy up)