Change usage of `self = this` to use arrow functions instead. Also fixes a reference error where `self` wasn't defined.