Better handling of ref targets; add RequireJS support