Closes #15 by checking validity of index