                 # choose newest in the datacenter -- this one is easiest to get up to date
                 dest = d[0]
                 for i in [1...d.length]
-                    if d[i].version > dest[i].version
+                    if d[i].version > dest.version
                         dest = d[i]
                 send
                     project_id : opts.project_id

        (cb) ->
            # dump range of snapshots
            start = if opts.dest.version then "-i #{f}@#{opts.dest.version}" else ""
            execute_on
                host    : opts.source.host
                command : "sudo zfs send -RD #{start} #{f}@#{opts.source.version} | lz4c -  > #{tmp}"
                cb      : (err, output) ->
                    winston.debug(output)
                    cb(err)
        (cb) ->
            # scp to destination

                command : "cat #{tmp} | lz4c -d - | sudo zfs recv #{force} #{f}; rm #{tmp}"
                cb      : (err, output) ->
                    winston.debug(output)
                    if output.stderr
                        err = output.stderr
                    cb(err)
        (cb) ->
            # update database to reflect the new list of snapshots resulting from this recv
            # We use repair_snapshots to guarantee that this is correct.
            repair_snapshots
                project_id : opts.project_id
                host       : opts.dest.host
                cb         : cb
    ], (err) ->
        # remove the lock file
        if clean_up
            execute_on
                host    : opts.source.host
                command : "rm #{tmp}"
                cb      : (ignored) ->
                    opts.cb?(err)
        else
            # no need to clean up -- bailing due to another process lock
            opts.cb?(err)
    )


