add Connection parameter to function die so that we could clean memory
before exit