Proving $ B(x) = 2 \sqrt{x} L(1, \chi) + O(1) $ where $ B(x) = \sum_{n \le x} \frac{1}{\sqrt{n}} \sum_{d \mid n} \chi(d) $ Theorem 6.20 of Introduction to Analytic Number Theory (Tom M. Apostol) states:

Theorem 6.20 For any real-valued nonprincipal character $\chi \bmod k$, let
$$ A(n) = \sum_{d\mid n} \chi(d) \hspace{2em} \text{ and } B(x) = \sum_{n \le x} \frac{A(n)}{\sqrt{n}}. $$
Then we have:
(a) $ B(x) \to \infty$ as $x \to \infty$.
(b) $ B(x) = 2 \sqrt{x} L(1, \chi) + O(1)$ for all $x \ge 1$.
Therefore $L(1, \chi) \ne 0$.

I have understood most of the proof that follows except a single step at the end and that single step seems to involve just addition of terms but I am unable to figure it out. I am presenting that single step at the end below:
\begin{align}
B(x)
&amp; = \sum_{n \le \sqrt{x}} \frac{\chi(n)}{\sqrt{n}} \left\{ 2\sqrt{\frac{x}{n}} + A + O\left( \sqrt{\frac{n}{x}} \right)\right\} \\
&amp; +
\sum_{n \le \sqrt{x}} \frac{1}{\sqrt{n}} \left\{ B + O\left(\sqrt{\frac{n}{x}}\right)\right\} - 2Bx^{1/4} + O(1) \\
&amp;= 2\sqrt{x} \sum_{n \le \sqrt{x}} \frac{\chi(n)}{n} + A\sum_{n \le \sqrt{x}}\frac{\chi(n)}{\sqrt{n}} + O\left(\frac{1}{\sqrt{x}} \sum_{n \le \sqrt{x}} | \chi(n) |\right) \\
&amp; +
B \sum_{n \le \sqrt{x}} \frac{1}{\sqrt{n}} + O\left(\frac{1}{\sqrt{x}} \sum_{n \le \sqrt{x}} 1\right) - 2Bx^{1/4} + O(1) \\
&amp;= 2\sqrt{x}L(1, \chi) + O(1).
\end{align}
How do we get $ 2\sqrt{x}L(1, \chi) + O(1) $ from the preceding step?
$ L(1, \chi) $ is defined as $ L(1, \chi) = \sum_{n=1}^\infty \frac{\chi(n)}{n} $, so it is a sum with infinite terms. But I don't see any sum with infinite terms in the preceding step. So how are we able to go from a step that does not have any infinite series to a step that has an infinite series?
For any $x&gt;1$ we have $$L(1,\chi)=\sum_\limits{n\leq\sqrt{x}}\frac{\chi(n)}{n}+\sum_\limits{n&gt;\sqrt{x}}\frac{\chi(n)}{n}.$$ Now using Theorem 6.18 we conclude that $$\sum_{n&gt;\sqrt{x}}\frac{\chi(n)}{n}=O\Big(\frac{1}{\sqrt{x}}\Big).$$
Thus we have $$L(1,\chi)+O\Big(\frac{1}{\sqrt{x}}\Big)=\sum_\limits{n\leq \sqrt{x}}\frac{\chi(n)}{n}.$$
For any $x&gt;1$ we have $$L(1,\chi)=\sum_\limits{n\leq\sqrt{x}}\frac{\chi(n)}{n}+\sum_\limits{n&gt;\sqrt{x}}\frac{\chi(n)}{n}.$$ Now using Theorem 6.18 we conclude that $$\sum_{n&gt;\sqrt{x}}\frac{\chi(n)}{n}=O\Big(\frac{1}{\sqrt{x}}\Big).$$
Thus we have $$L(1,\chi)+O\Big(\frac{1}{\sqrt{x}}\Big)=\sum_\limits{n\leq \sqrt{x}}\frac{\chi(n)}{n}.$$