Fixing nodejs error where lines will sometimes be undefined