no more segfaults, all test cases correct; todo: pretty print