added some validity checks