Add error checking to prevent crashes on bad files