refactor duplicate code in watch functions