get rid of segfault on X button by making die().
also clean things up a bit