Refactor locate_file function

- fix bug with global scope attachment
- immediate return if index
- remove lodash dep