move functions to commonjs modules

closes #355