added some error handling to initialization