almost finish r.js impl