Refactoring and example updates to suit NPM packaging