refactor to use templates for popups