Added error handling and InvalidFileType object