something is wrong with this algorithm