Fix various minor bugs uncovered during testing