Adapted for latest version of SP Client