Fix several minor bugs.