Basically finished algorithm.
Documentation.