added nil-pointer- and bound-checking for arrays