refactoring: moved code for watch mode to separate function