Binary-search in path + some speedup improvements. Speedup is only negligible :/