Rework to fix AMD and r.js issues.
Implements @millermedeiros' solution to fix #42. Closes #60, #59 and #58.