Added safety check for empty files.