Complete commonjs implementation - working version