clearline algorithm modified