Reshaped Algorithm