added some error handling/logging, still not ideal