Added generic algorithm.