Changed to use factory method for AMD and commonjs support!