Added checks for potential problems when listing files