Added some AMD wrapping functionality. Could be cleaned up and made more generic.