Fix a couple bugs, add logging