Segfault fix + small calculation fix