Fix for "Cannot call method 'close' of undefined".