refactor last line indexOf method