initial refactor for npm publishing

still a lot of code to be cleaned up, this is only tested locally on OSX.

TBD: 
* testing on Linux from npm install. 
* documentation!