error checking funtion added