Quick update this code needed to be rectified - see here TypeError: Cannot read property 'length' of undefined