added refactored logic for main page