Extracted logic out into its own npm module.