Improve thread safety

Using @@ is not thread safe. Either connection instance variables (since each thread is guaranteed to have it's own connection) or thread local variables (Thread.current[VAR]) is safer.