Improvement of the algorithm in alloc 2