rewrite ``locateat`` function according to @timholy