fixed some bugs/errors but still segmentation fault at runtime