Fix some bugs, add log output to csv