Refactored template dir update code