The algorithm is more generic, now