Refactor JS 'this' mess.