Added handling for KeyboardInterrupt

Now the program can safely be stopped using KeyboardInterrupt, all of
the current results will be written to the database before exiting