Fix for TypeError: undefined is not a function