Fixed socket not being closed