instead of working dir now LogFilename is used.

Also code style corrections and minor refactoring.