Updated algorithm to give better results.
Updated documentation.