Restructured code in present to find bug (bug vanished, but I don't see why). Made mkdir_p a little bit more fault tolerant.