implemented most of index.js