Fix TypeError: undefined is not a function