change perror to fprintf