Fixed bugs and altered index.js to allow for buffer