Refactor to store templates in a map and then detach from dom