Moved the line parsing into a separate method to avoid code duplication.