refined the logic in main.js and the app.s.