Refactored code with VeilMatrix prototype