reviewed version of algorithms