Revised code to avoid some potential issues.