improve template watch and build logic