added login popup and refactored code