updated to check for bad values