common algorithm Implementation