Refactor to use `self.` instead of global vars