perror() in error() and refactor