Modifications to handle unusual files

Small changes to handle some edge cases.