Sometimes, the BlockByTimestamp method does not work. I think this is because the algo tries to estimate a distance of blocks based on the average block time, but this can result in getting stuck when it jumps between 2 blocks, with no changes. There should probably be some variability to the estimated block number to make sure this doesn't happen.