First (rough) import of the algorithm