Remove dependency on Array.getLength()