Convert index.js to a function for easier programmatic usage