Clean some things up, factor resource.js better, and try to be less error-prone.