added some error prevention