refactor to cleanup index.js