Fixing a minor bug in AMD support. Also added redundancy check on root in the main factory function