Cleaned up the exit code using the atexit module
--amend
Revert "--amend"

This reverts commit 0d3231f3e1e71ed2200634d7b0852d1e6ae8adfb.

Oops... My bad :P
Fixed the accidental camelcasing
Fixed an error with closed connections