added the algorithm for conversion