Fix core dump and compiler warnings