algorithm modified