Getting closer to working. Browser crashes when checking null array elements