Fixes issue #4, connection now closes properly