fixed error with missing variable and add spec test to catch this next time