Bug fixes in index.js