Basic algorithms.