moved to commonjs, refactored js