Fixed segfault issue
Corrected errors from -pedantic