Add a check before parsing invalid data
Fix some tests