fixed all compile errors, still segmentation fault