manfred changes, better structure to algorithms