Add comments and make setResource chainable
Change to refer self instead of this
Fix tests