Reorganize code to work better as a global npm module