adding keith's code, exit closes whole application