Extract watch handler to a function