Refactor: write file indets function