minor changes to Algo 1