Several small fixes, no more segmentation faults found.