Added conditional to prevent writing past vaild array address space