add more check to avoid crashing