refactor move out stuff from index.js