Added daemonising code.
Removec unecessery code.
Added a parameter for an arbitrarty commmand to be executed after the logging has finished.