Fix various minor bugs