Working project with segfault on exit