Edited destructor to try closing device only when initialized