ported js to use require to improve dependency management