[FIX] Add control flow to index.js