Refactored the line_completed handler a bit.