Fixed a bug where the wrong side of the connection was closed