completed code, segfaults