fixed a bug with implementing perror