Added some connection disposing and exception handling