added some error processing