Refactoring of the popup directive and service