Added popup and refactored