Clean up index.js
Separate filter logic from index