Ported batch to use connection as an argument