Refactored the code to be more testable and updated tests accordingly
mocked HTTPRequest and updated test testScanWithInvalidApiKey