Refactor everything into index.js, made it work