Solved some bugs with the memory managment to avoid SegFaults.