Fix various small bugs