Possible final version of driver program

Feel free to add more comments explaining the inner workings of the
functions, if you think that they are not sufficient.