Fix some bugs uncovered in review