Fixed issue with abruptly closing the scanner.