added error handling with perror and some more warning fixes