changed some stuff around, fixed a segfault