Allows cleaner exit when closed

Before, closing the app left the processes just hanging. This patch allows the program to exit cleanly when closed from another source.