Refactor the code that prevents a circular template extension error