Rewrite lib/index.js

Makes it a bit more readable and easier to maintain.
Haha, lol. Didn't think of that.