Added try except blocks to catch invalid files