Bugfix for unclosed socket. Socket will now closed before application exits.