Example cleanup

memory leaks and segfaults