* add quite a lot of debugging output and a logging mechanism to log to a file