made major changes in order to fix a segfault, fixed now :)