modified to fix bug by testing loc and integer indices