added to_optimized_goal algorithm