Fixed a warning in non-interactive mode.
Factorized some code.