Fixed a nullpointerexception when closing connections.