Fix several bugs.