Added exception at connect. Added proper shutdown of program.