Refactored click handler code in index.js