added some error validation