improve handling of malformed data

fixes #45