refactor and added popup