npm build system (unfinished), misc refactoring