Fixes Uncaught TypeError: Cannot read property 'length' of undefined error

Resubmission of #47