Changed generate-algorithm