add "|| line.empty()" to the if condition to correctly process empty lines