Added code to handle figure handles that don't close automatically