Refactor monolithic convert function.