thus the algorithm should have been quite simple