refactor to a npm module