Added credit to Guido Governatori for his algo.