Modified algorithm