Improve code of popup service