Revised algorithm section