complete the match line algorithm