refactor, add to npm and generation script