@SuppressWarnings("unchecked")
    public void removeAt(int index) {
        E[] temparray = (E[]) new Object[array.length - 1];

        if (index == 0) {
            // Copy everything except first element
            System.arraycopy(array, 1, temparray, 0, array.length - 1);


        } else if (index == array.length - 1) {
            // Copy everything except last element
            System.arraycopy(array, 0, temparray, 0, array.length - 1);

            if (lastPos == index) {
                --lastPos;
            }

        } else if (indexOK(index)) {
            // Assume deletion at index = 3
            // 0 1 2 3 4 5 6 7 8 9
            // _ _ _ x _ _ _ _ _ _

            // 0 1 2 _ _ _ _ _ _
            System.arraycopy(array, 0, temparray, 0, index);

            // _ _ _ 4 5 6 7 8 9
            System.arraycopy(array, index + 1, temparray, index, array.length - 1 - index);
            // Result:
            // 0 1 2 4 5 6 7 8 9

        } else {

            throw new IndexOutOfBoundsException("Cannot delete element - invalid index passed: "
                    + index + "not in 0..." + (array.length - 1) + " range.");
        }


        array = temparray;


        while (array[lastPos] == null && lastPos > 0) {
            --lastPos;
        }
    }