re-organized algorithms