fixed some segfaults, still messing up at fopen, something to do with the path I think