add "|| key.empty()" to the if condition to process correctly case with empty key line