added some better checking