save a function call by checking if index is not null