Update factory.js

Cleans up factory.js to work the new way, should also fix the windows incompatibility in #345