added log file stuff and some debugging output