Fix several minor bugs