Segfault solved, slow algorithm