Added dirty checking to quit