added a missing close and using, and added some logging