algorith patched, except for sorting population