refactoring for better commonjs support