At about this point, I would do a check for empty arrays and do an early return if that is the case. I can easily imagine a case of inputs being all masked out.