Added comments, fixed/shortened some functions. When quitting the WM exists cleanly.