segfault, messed up logic somewhere...