Simple working algorithm.