improved error handling for badly formed files