Fix a few bugs in last commit