Amended fix for arrays shorter than keys length