Added a check for error code returned from the request.get function. Otherwise when there is a connection error there is a problem with request.statusCode as request is null.
Added fix for the memory leak and a test example from a discussion about the issue.
Merge pull request #22 from seanowenhayes/master

Check for connection error in main.