Fixed problem with connection getting closed properly.
Tweaked connection closing