Wrote is_invalid function