changed the add() and calcIndex() methods