added a quit function and starting to work out the exit program function