Fixed bug where uncaught typeerror occurred #1012