the previous algorithm is wrong, revert to original