Refactor ProcessLine into a ProcessLoop