fixed issue with file magic lookups, added error handling