added logfile and other improvements