Fix unexpected end-of-object raising NoMethodError