refactored and made the quit function work correctly 4/23/14