Fixed error about using $this outside of object context