fixed bugs in index.js