Added a check to prevent null keys