Make data import more robust

This adds a few checks and makes the whole import more robust against errors and/or misformed input.