Revised calcIndex and wrote part of add.